package org.lonetree.tc.core;

import org.lonetree.tc.core.id.NumericalId;

/**
 * JAVADOC BookComment
 *
 * @author xeon
 *
 */
public final class BookComment extends Comment{
	
	public BookComment(Book parentBook, User user, String comment, boolean flagged){
		this(null, parentBook, user, comment, flagged);
	}

	protected BookComment(BookCommentId bookCommentId, Book parentBook, User user, String comment, boolean flagged){
		super(bookCommentId, parentBook, user, comment, flagged);
		
		parentBook.getComments().add(this);
	}
	
	/**
	 * JAVADOC BookComment.getBookCommentId()
	 *
	 * @return
	 */
	public BookCommentId getBookCommentId(){
		NumericalId id = getNumericalId();
		if(id instanceof TempId)
			return null;
		else
			return (BookCommentId)getNumericalId();
	}
	
	protected void setBookCommentId(BookCommentId bookCommentId){
		setIdentifier(bookCommentId);
	}
	
	/**
	 * JAVADOC BookComment.getParentBook()
	 *
	 * @return
	 */
	public Book getParentBook(){
		return (Book)getParentItem();
	}

	@Override
	protected String getIdentifierType(){
		return "bookCommentId";
	}
	
	/**
	 * JAVADOC BookCommentId
	 *
	 * @author xeon
	 *
	 */
	public static class BookCommentId extends NumericalId{

		/**
		 * JAVADOC BookCommentId.BookCommentId()
		 *
		 * @param bookCommentId
		 * @throws ValidationException
		 */
		public BookCommentId(long numericalId) throws ValidationException{
			super(numericalId, INFINITE_LENGTH_ALLOWED);
		}
		
		/**
		 * JAVADOC BookCommentId.BookCommentId()
		 *
		 * @param numericalId
		 * @throws ValidationException
		 */
		public BookCommentId(String numericalId) throws ValidationException{
			super(numericalId);
		}
		
		/**
		 * JAVADOC BookCommentId.getBookCommentIdLong()
		 *
		 * @return
		 */
		public Long getBookCommentIdLong(){
			return getNumericalIdLong();
		}
	}
}
